﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Cos.Core.Model.Media;
using Cos.Core.NHibernate;
using Cos.Module.Media.Data;
using Cos.Module.Media.Exceptions;
using NHibernate;

namespace Cos.Module.Media.NHibernate
{
    public class MediaRepository : RepositoryBase, IMediaRepository
    {
        public MediaRepository(ISessionFactory sessionFactory) 
            : base(sessionFactory)
        {
        }

        public Video GetVideo(int videoId, string cultureCode, bool isLiveMode)
        {
            // Get the data from the database
            var video = this.CurrentSession.Get<VideoDataModel>(videoId);
            if (video == null)
            {
                throw new VideoNotFoundException("Not such video in the database. Video.ID: " + videoId);
            }

            var culture = this.CurrentSession.Get<CultureDataModel>(cultureCode);
            if (culture == null)
            {
                throw new VideoNotFoundException("Not such video in the database. Culture.CultureCode: " + cultureCode);
            }

            return video.ToModel();
        }
    }
}
